package com.example.shop.utils;

/**
 * @projectName: travel
 * @package: com.example.travel.utils
 * @className: UserNameVerify
 * @author: Liqian
 * @description: TODO
 * @date: 2024/4/11 12:22
 * @version: 1.0
 */

import java.util.regex.*;

public class UserNameVerify {

    public static boolean isValidString(String input) {
        // 定义正则表达式，表示4-10位数字或英文字符的组合
        String regex = "^[a-zA-Z0-9]{4,10}$";

        // 编译正则表达式
        Pattern pattern = Pattern.compile(regex);

        // 创建 Matcher 对象
        Matcher matcher = pattern.matcher(input);

        // 进行匹配和校验
        return matcher.matches();
    }

    public static void main(String[] args) {
        String[] testStrings = {"abc123", "Hello123", "ab12", "1234567890 ", "ab "};

        for (String str : testStrings) {
            boolean isValid = isValidString(str);
            System.out.println("String '" + str + "' is valid? " + isValid);
        }
    }
}

